package client_service

/**
* @author aFun
* @data 2025/4/12 12:33
* @email: afunaaa222@163.com / 1030935903
* @address: Guangdong University of Technology, China
 */

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func ShowMenu() {
	for true {
		fmt.Println(`
				█████╗  ███████╗ ██╗   ██╗ ███╗   ██╗
			   ██╔══██╗ ██╔════╝ ██║   ██║ ████╗  ██║
			   ███████║ █████╗   ██║   ██║ ██╔██╗ ██║
			   ██╔══██║ ██╔══╝   ██║   ██║ ██║╚██╗██║
			   ██║  ██║ ██║      ╚██████╔╝ ██║ ╚████║
			   ╚═╝  ╚═╝ ╚═╝       ╚═════╝  ╚═╝  ╚═══╝
			
			┌────────────────────────────────────────────┐
			│ 1. Request User Info                       │
			│ 2. Show Floor Rewards                      │
			│ 3. Show Cumulative Rewards                 │
			│ 4. Lucky Draw                              │
			│ 5. Claim Floor Reward                      │
			│ 6. Claim Cumulative Reward                 │
			│ 7. Logout                                  │
			└────────────────────────────────────────────┘
			Please enter an option:`)

		fmt.Print("请输入编号进行操作: ")
		var key int
		_, err := fmt.Scanf("%d\n", &key)
		if err != nil {
			reader := bufio.NewReader(os.Stdin)
			reader.ReadString('\n') // 读取缓冲区并丢弃，不然输出多个错误时会触发多次
		}
		switch key {
		case 1:
			err := Eoutput_self_lucky_draw_data()
			if err != nil {
				fmt.Println(err)
			}
		case 2:
			err := Eoutput_floor_lucky_draw_data()
			if err != nil {
				fmt.Println(err)
			}
		case 3:
			err := Eoutput_cumulative_lucky_draw_data()
			if err != nil {
				fmt.Println(err)
			}
		case 4:
			var isProtected uint
			for {
				fmt.Println("0代表普通抽奖 1代表保护抽奖")
				_, err := fmt.Scanf("%d\n", &isProtected)
				if err != nil {
					reader := bufio.NewReader(os.Stdin)
					reader.ReadString('\n') // 读取缓冲区并丢弃，不然输出多个错误时会触发多次
				}
				if isProtected != 0 && isProtected != 1 {
					fmt.Println("无效输入")
					continue
				} else {
					flag := false
					if isProtected == 1 {
						flag = true
					}
					err = Edraw(flag)
					if err != nil {
						fmt.Println(err)
					}
					break
				}
			}
		case 5:
			var floor int8
			var pos int8
			_, err := fmt.Scanf("%d %d", &floor, &pos)
			if err != nil {
				return
			}
			reader := bufio.NewReader(os.Stdin)
			reader.ReadString('\n') // 读取缓冲区并丢弃，不然输出多个错误时会触发多次
			err = Eget_floor_reward(floor, pos)
			if err != nil {
				fmt.Println(err)
			}
		case 6:
			var indexes []int64
			fmt.Println("输入领取的编号")
			reader := bufio.NewReader(os.Stdin)
			line, _ := reader.ReadString('\n')
			line = strings.TrimSpace(line)
			strNums := strings.Fields(line)
			for _, s := range strNums {
				n, err := strconv.ParseInt(s, 10, 64)
				if err != nil {
					fmt.Println(err)
					continue
				}
				indexes = append(indexes, n)
			}
			err = Eget_cumulative_reward(indexes)
			if err != nil {
				fmt.Println(err)
			}
		case 7:
			err = Logout()
			if err != nil {
				fmt.Println(err)
			} else {
				fmt.Println("退出系统咯！")
				os.Exit(0)
			}

		}
	}
}
